﻿/*
    Copyright 2010, 2011 Eric Wong
	contact@optimalcycling.com
	http://www.optimalcycling.com
	Optimal Cycling - Advanced power pacing program for cyclists
	
	This file is part of Optimal Cycling.

    Optimal Cycling is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Optimal Cycling is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Optimal Cycling.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _FILE_MODEL_H_
#define _FILE_MODEL_H_

#ifndef __OPENCL_VERSION__
	#include "Options.h"
	#include "Constants.h"
	#include "Vector.h"
	#include "Interpolate.h"
#endif

#define KERNEL_VARS_TO_MODEL coursePosPoints, coursePosLinear, coursePosLinearMax, \
	coursePosDirection, coursePosInfo, riderProp, wind, climate, \
	numSimPoints, dragCoeffWheelYawAngles, dragCoeffWheels, dragCoeffWheelsNumPts, modelInfo

/// <summary>
/// What to use to solve the second order differential equation of motion
/// </summary>
typedef enum 
{
    Nystrom,
    Beeman,
    RKF45
} IntegrationMethods;

/// <summary>
/// What type of bearing resistance model to use
/// </summary>
typedef enum 
{
    BearingResistance_CartridgeBearingDahn,
    BearingResistance_None
} BearingResistance;


/// <summary>
/// Holds the model information that stays the same for the simulation
/// </summary>
typedef struct 
{
	real minSpeed;
	real initialSpeed;
	real massTotal;
	real weightTotal;
	real massAndRotInertiaTotal;
	real inverseMassAndRotInertiaTotal;
	real driveTrainEfficiency;
	real CdA;
	real halfCdA;
	real diameterFrontWheel;
	real diameterSqFrontWheel;
	real rotInertiaFrontWheel;
	real diameterRearWheel;
	real diameterSqRearWheel;
	real rotInertiaRearWheel;
	real rearWheelShieldingFactor;
	real oneMinusRearWheelShieldingFactor;
	int stillWind;
} ModelInfo;

inline int ModelAcceleration(real4* iData,		// iTime {s0}, iPosition {s1}, iSpeed {s2}, iAccel {s3}
		real* iPower, 
		__global const real* powerVal,
		__global const real4* coursePosPoints, 
		__global const real* coursePosLinear,
		const real coursePosLinearMax,
		__global const real4* coursePosDirection,
		__global const real4* coursePosInfo, 
		__global const real4* riderProp,
		__global const real4* wind, 
		__global const real4* climate,
		const sizeT numSimPoints,

		__global const real* dragCoeffWheelYawAngles,
		__global const real2* dragCoeffWheels, 
		const sizeT dragCoeffWheelsNumPts,

		__global const ModelInfo* modelInfo);

#endif		// _FILE_MODEL_H_



